import SwiftUI
import SPGlassKit

public struct GlassSheetExample: GlassExample {
    public static let componentID = "glass-sheet"
    @State private var showsFilters = false
    @State private var showsTerms = false
    @State private var keyword = ""
    @State private var onlyAvailable = true

    public init() {}

    public var body: some View {
        VStack(spacing: 16) {
            GlassButton("Filters", systemImage: "line.3.horizontal.decrease") { showsFilters = true }
            GlassButton("Terms of use") { showsTerms = true }
        }
        .padding()
        .glassSheet(isPresented: $showsFilters, title: "Filters", configuration: .halfAndFull) {
            Form {
                TextField("Keyword", text: $keyword)
                Toggle("Only available", isOn: $onlyAvailable)
            }
        }
        .glassSheet(
            isPresented: $showsTerms,
            title: "Terms of use",
            configuration: GlassSheetConfiguration(detents: [.fraction(0.4), .large], isInteractiveDismissDisabled: true)
        ) {
            ScrollView {
                Text("Sample terms. This sheet cannot be swiped away: the close button is the way out.")
                    .frame(maxWidth: .infinity, alignment: .leading)
                    .padding()
            }
        }
    }
}

#Preview("GlassSheet") { GlassSheetExample() }
